define(function(require,exports,module){
	var aw = require("ajaxwrapper");
	var Dialog =require("dialog");
	
	module.exports = {
		handleSaveBtnClick: function(widget){
			
		},
		handleSetBtnClick: function(widget,data){
			widget.show([".J-form"]).hide([".J-checkgrid"]);
			widget.get("form").setDisabled(true);
			widget.get("subnav").show(["return"]).hide(["search", "servicePoint", "status", "startDate"]);
			var dataSource = data.dataSource.key;
			widget.set("dataSource", dataSource);
			if(dataSource == "GroupReserve"){	//老人团
				widget.show(".J-grid");
				widget.set("pkCheckInImplement", data.pkCIImplement);
				widget.get("form").setData({
					reserveType : "老人团",
					groupUnit : data.groupReserve.planItemGroup.allianceOrg ? 
							data.groupReserve.planItemGroup.allianceOrg.name : 
								data.groupReserve.planItemGroup.servicePoint.name,
					desName : data.groupReserve.planItemGroup.planItem.destination.name,
					signUpNumber : data.signUpNum,
					checkInDate : moment(data.groupReserve.checkInDate).format("YYYY-MM-DD"),
					checkOutDate : moment(data.groupReserve.checkOutDate).format("YYYY-MM-DD"),
					description:data.groupReserve.description
				});
				widget.get("grid").refresh();
			}else if(dataSource == "NonMember"){	//散客
				widget.set("pkNonMemGroupReserve", data.nonMemGroupReserve.pkNonMemGroupReserve);
				widget.show(".J-roomtypegrid");
				var groupUnit = "";
				var signUpType = data.nonMemGroupReserve.nonMemberGroup.signUpType.key;
				groupUnit = data.nonMemGroupReserve.nonMemberGroup.contactName;
				widget.get("form").setData({
					reserveType : "散客团",
					groupUnit : groupUnit,
					desName : data.nonMemGroupReserve.nonMemberGroup.servicePoint.name,
					signUpNumber : data.signUpNum,
					checkInDate : moment(data.nonMemGroupReserve.nonMemberGroup.checkInDate).format("YYYY-MM-DD"),
					checkOutDate : moment(data.nonMemGroupReserve.nonMemberGroup.checkOutDate).format("YYYY-MM-DD"),
					description:data.nonMemGroupReserve.nonMemberGroup.description
				});
				widget.get("roomTypeGrid").refresh();
			}
			
		},
		handleDetailBtnClick: function(widget,data){
			this.handleSetBtnClick(widget,data);
			var dataSource = widget.get("dataSource");
			if(dataSource == "NonMember"){
				$(".J-grid-head-formel").hide();
    			$("th[data-name='show']").addClass("hidden");
    			$(".J-grid-columns-show").addClass("hidden");
			}
			if(dataSource == "GroupReserve"){
				$(".J-grid-head-formel").hide();
			}
			widget.get("subnav").hide(["save"]);
		},
		pendDataHandler : function(data, widget, flag){
			var pendDescription=""
			if(data.roomRegister.pendDescription){
				pendDescription = data.roomRegister.pendDescription
			}
			widget.hide([".J-grid", ".J-form"]).show([".J-detailgrid"]);
			if(flag){
				widget.get("subnav").hide([]).show(["return","save"]);
			}else{
				widget.get("subnav").hide([]).show(["return"]);
			}
			widget.set("edit", true);
			widget.set("curData",data);
			widget.get("editgrid").setData([{
    			key: "water",
    			items: "水",
    			isChecked: data.roomRegister.water
    		},{
    			key: "electric",
    			items: "电",
    			isChecked: data.roomRegister.electric
    		},{
    			key: "telephone",
    			items: "电话",
    			isChecked: data.roomRegister.telephone
    		},{
    			key: "wireless",
    			items: "宽带",
    			isChecked: data.roomRegister.wireless
    		},{
    			key: "pendDescription",
    			items:"<textarea style='width:100%;' id='pendDescription'>"+pendDescription+"</textarea>"
    		}]);
		}
	};
})